#include <bits/stdc++.h>
// 2025/06/11
// tag: 
// Author: Forever
using namespace std;
using int64 = int64_t;

#define int long long
const int N = 100001;
int n, k, c[N], f[N][25], d[N][25];
vector<int> edge[N];

void dfs(int u, int fa){
    for (int i = 0; i <= k; i++)
        f[u][i] = c[u];
    for (int v : edge[u]){
        if (v == fa)
            continue;
        dfs(v, u);
        for (int i = 0; i <= k; i++)
            f[u][i] += f[v][i - 1];
    }
}

void dfs2(int u, int fa){
    for (int v : edge[u]){
        if (v == fa)
            continue;
        for (int i = 0; i <= k; i++)
            d[v][i] += d[u][i - 1] - f[v][i - 2];
        dfs2(v, u);
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) 
        cin >> c[i];
    dfs(1, 0);
    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= k; j++)
            d[i][j] = f[i][j];
    dfs2(1, 0);
    for (int i = 1; i <= n; i++)
        cout << d[i][k] << endl;
    return 0;
}